﻿using System.Collections.Generic;
using System.Linq;
using Interface;

namespace Model
{
    public class FbmReportCollection // This class is written by Per Leth Andersen
    {
        public List<FbmReport> ReportCol { get; set; }

        public FbmReportCollection()
        {
            ReportCol = new List<FbmReport>();
        }

        #region Methods
        public FbmReport Add(int id, IRid rid, string serial, string model, string mident, string mPart, string reportFileName)
        {
            FbmReport _fbmReport = new FbmReport(id, rid, serial, model, mident, mPart, reportFileName);
            ReportCol.Add(_fbmReport);
            return _fbmReport;
        }
        public FbmReport Find(int id) // Find one specific report:
        {
            int max = ReportCol.Count;
            int min = 0;
            while (max >= min)
            {
                int mid = (min + max) / 2;
                if (ReportCol[mid].Id < id)
                    min = mid + 1;
                else if (ReportCol[mid].Id > id)
                    max = mid - 1;
                else
                    return ReportCol[mid];
            }
            return null;
        }
        public IFbmReport Find(string model)
        {
            return ReportCol.Where(report => report.Model == model).Cast<IFbmReport>().FirstOrDefault();
        }
        #endregion
    }
}